package repository.relsys.util.json;

import java.util.Collection;
import java.util.List;

import repository.relsys.domainmodel.ltool.interfaces.LearningTool;
import repository.relsys.util.json.nodes.DescriptionNode;
import repository.relsys.util.json.nodes.SimpleDescriptionNodeFactory;

import com.hp.hpl.jena.sparql.lib.org.json.JSONArray;
import com.hp.hpl.jena.sparql.lib.org.json.JSONException;
import com.hp.hpl.jena.sparql.lib.org.json.JSONObject;

public class JSONExporterCls implements JSONExporter {

	public JSONObject convertLTToJSON(Collection<LearningTool> learningTools)
			throws JSONException {
		JSONObject jobj = new JSONObject();
		JSONArray curArray = new JSONArray();

		for (int i = 0; i < learningTools.size(); i++) {

			JSONObject obj = new JSONObject();

			LearningTool currentltools = ((List<LearningTool>) learningTools)
					.get(i);

			DescriptionNode node = new SimpleDescriptionNodeFactory()
					.createNode(currentltools);

			obj.put("label", node.getTitle());
			obj.put("type", "LearningTool");
			obj.put("description", node.getDescription());
			obj.put("toolURL", node.getToolURl());
			obj.put("toolImgURL", node.getToolImgURl());
			obj.put("cost", node.getToolCost());
			obj.put("availability", node.getToolAvailability());
			obj.put("openSource", node.isOpenSource());
			obj.put("launched", node.getLaunchedTime());
			obj.put("registration", node.registration());
			obj.put("hasFeature", node.getFeaturesTitle());
			obj.put("supportedMobileDevices", node.getMDTitle());
			obj.put("supportedOS", node.getOSTitle());

			curArray.put(obj);
			jobj.put("items", curArray);
		}
		return jobj;
	}
}
